package com.amc.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import com.amc.dto.ComplaintView;
import com.fasterxml.jackson.databind.ObjectMapper;

public class ComplaintCommit {
		public List<String> complaintCommit(ComplaintView complaint){
			HttpURLConnection conn;
			List<String> list = new ArrayList<>();
			ObjectMapper mapper = new ObjectMapper();
			try {// 10.222.29.195
				URL url = new URL(
						"http://10.222.29.195:8080/amc-a-v3/admin/complaint/doComplain?merchantId="
								+ complaint.getMerchantId() + "&customerId="
								+ complaint.getCustomerId() + "&complaintText="
								+ complaint.getComplaintText() + "&complaintTime=");
				conn = (HttpURLConnection) url.openConnection();
				conn.setRequestMethod("POST");
				conn.setDoOutput(true);
				conn.setDoInput(true);
				conn.connect();		
				int resCode = conn.getResponseCode();
				if (resCode == 200) {			
					InputStream is = conn.getInputStream();
					BufferedReader br = new BufferedReader(
							new InputStreamReader(is));
					String line = "";
					String result = "";
					while ((line = br.readLine()) != null) {
						result += line;
					}
				}
				// list = mapper.readValue(result, List.class);
			} catch (IOException e) {
				System.out.println("服务器未开启，投诉失败");
//				e.printStackTrace();
			}

			return list;
		}
}
